import { MenuEntity } from '@/src/menu/entities/menu.entity'
import { Entity, PrimaryGeneratedColumn, Column, Index, ManyToOne, JoinColumn } from 'typeorm'

@Entity('favorite')
export class FavoriteEntity {
  @PrimaryGeneratedColumn()
  id: number

  @Column()
  @Index() // 添加索引提高查询效率
  user_id: number

  @Column()
  @Index()
  menu_id: number

  @Column({ default: Math.floor(Date.now() / 1000) })
  create_time?: number

  @ManyToOne(() => MenuEntity, menu => menu.favorites)
  @JoinColumn({ name: 'menu_id' })
  menu: MenuEntity
}